/**
 * @file obj_data.h
 * @author YangSL (dalin@main.com)
 * @brief 
 * @version 0.0.1
 * @date 2022-09-28
 * 
 * @copyright Copyright (c) 2022
 * 
 */
#ifndef _OBJ_DATA_H_
#define _OBJ_DATA_H_

#include "basetype.h"
// #include "data.h"

/*FUN ID*/
#define       SDO_RX_ID    0x600    /* 作为服务器发送数据 */
#define       SDO_TX_ID    0x580    /* 作为客户端发送数据 */

#define       PDO1_TX_ID   0x181
#define       PDO2_TX_ID   0x281
#define       PDO3_TX_ID   0x381
#define       PDO4_TX_ID   0x481
#define       SDO_FRAME_LEN  0x08
/*component ID*/
#define       COMP_NUMS         e_comp_max
#define       IPC_ID            0x01
#define       NODE1_ID    		0x02 
#define       NODE2_ID      	0x03

/*需要根据板子配置id*/
#define       CUR_MASTER_ID     NODE1_ID  /*本机ID*/

/*attribute*/
#define       CAN_RO                0x01
#define       CAN_WO                0x02
#define       CAN_RWS               0x03
  
#define   SELECT_PDO_OBJ_LEN(port)   pdo_obj_len[port]
#define   SELECT_SDO_OBJ_LEN(port)   sdo_obj_len[port]
#define   SELECT_COMPONENT(port)     comp_id[port]
enum ecomp_num
{
    e_comp_mc = 0 ,
    e_comp_max
};
typedef uint8 (*objFun)(void *) ;
#pragma pack(1)

typedef struct 
{
    uint16_t index ;
    uint8_t  subindex;
    uint16_t data_len ;
    uint8_t  attri;
    uint8_t  *ptr_data;
    objFun   r_callback;
    objFun   w_callback;
}sSDO_OBJ;

typedef struct 
{
    uint16_t  m_fun_id;
    uint8_t   frame_len;
    uint8_t   *ptr_data;
    objFun    callback;
}sPDO_OBJ; 

typedef struct
{
    uint8_t m_obj_id ;
    sSDO_OBJ *sdo_obj ;  
    sPDO_OBJ *pdo_obj ;   
}sComponent_OBJ;

#pragma pack()

extern  uint8_t pdo_obj_len[e_comp_max];
extern  uint16_t sdo_obj_len[e_comp_max];
extern  uint16_t comp_id[COMP_NUMS];
extern sComponent_OBJ  comm_data_map_obj[e_comp_max];
uint16_t crc16(uint8_t *data, uint32_t len);
void obj_data_init(void);
void can_protocol_init(void);
#endif

